<?php

function validate(&$var,$expType=NULL, $min=NULL, $max=NULL,$can_be_null=TRUE)
{   
    $correctType=FALSE;
    $expType=explode(',',$expType);
    $realType=  gettype($var);
    if(!$can_be_null && ($var==NULL || $var=='')) return ' can\'t be null';
    else{ 
        foreach ($expType as $eType)
            if ($eType==$realType) $correctType=TRUE;
        if(!$correctType) return ' is invalid';
        if ($realType=='string'){
            $var=trim($var);
            $len=strlen($var);
            if($min)
                if($len<$min) return ' is too short';
            if($max)
                if($len>$max) return ' is too long';
        }
        else if($realType=='double' || $realType=='integer'){
            $len=$var;
        if($min)
            if($len<$min) return ' is too low';
        if($max)
            if($len>$max) return ' is too high';
        }
        else 
            return ' is invalid';
    return NULL;
    }
}
?>
